import { h } from 'vue'

export function InitModel(Type) {
    var _TypeArray = Type.split(':') || [];
    var First = _TypeArray.shift();
    var Last = _TypeArray.join(':');
    return {
        FirstName: First,
        LastName: Last,
    }
}


export function FormatItemTypeString(str, Mapping) {

}


export function FormatViewTypeString(str) {
    if (str.indexOf(':') != -1) {
        var strArray = str.split(':') || [];
        return {
            ViewType: strArray[0],
            Key: strArray[1]
        }
    } else {
        return {
            ViewType: null,
            Key: str
        }
    }
}


// 执行判断条件的方法
export const StringToRule = (string, Object) => {
    var keyArray = [];
    var ValueArray = [];
    for (const key in Object) {
        keyArray.push(key);
        ValueArray.push(Object[key]);
    };
    try {
        return !!new Function(keyArray.join(','), 'return ' + string).apply(null, ValueArray);
    } catch (error) {
        console.error('StringToRule => Rule 字段配置错误', string, error);
    }
}

// 执行 基于对象的字符串方法
export const StringToFun = (string, Object) => {
    var keyArray = [];
    var ValueArray = [];
    for (const key in Object) {
        keyArray.push(key);
        ValueArray.push(Object[key]);
    };
    try {
        return new Function(keyArray.join(','), 'return ' + string).apply(null, ValueArray);
    } catch (error) {
        console.error('StringToFun => Rule 字段配置错误', string, error);
    }
}

